package cn.itcast.mq.listener;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * TODO
 *
 * @Authot mr.wu
 * @Date 2025/1/5 11:18
 */
@Component
public class SpringRabbitListener {

    /**
     * 简单模型 - 消费者
     * @param msg
     */
    @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueue(String msg) {
        System.out.println("消费者接收到simple.queue的消息：" + msg);
    }

    /**
     *工作队列 - 消费者1
     */
    @RabbitListener(queues = "work.queue")
    public void listenWorkQueue1(String msg) throws InterruptedException {
        System.out.println("消费者1接收到work.queue的消息：" + msg);
        TimeUnit.MICROSECONDS.sleep(20);
    }

    /**
     *工作队列 - 消费者2
     */
    @RabbitListener(queues = "work.queue")
    public void listenWorkQueue2(String msg) throws InterruptedException {
        System.out.println("消费者2接收到work.queue的消息：" + msg);
        TimeUnit.MICROSECONDS.sleep(20);
    }

    /**
     *广播模型 - 消费者1
     */
    @RabbitListener(queues = "fanout.queue1")
    public void fanoutQueue1(String msg)  {
        System.out.println("消费者2接收到work.queue的消息：" + msg);
    }

    /**
     *广播模型 - 消费者2
     */
    @RabbitListener(queues = "fanout.queue2")
    public void fanoutQueue2(String msg)  {
        System.out.println("消费者2接收到work.queue的消息：" + msg);
    }

}
